home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / cenvid.zip / DELTREE1.BAT < prev    next >
DOS Batch File  |  1993-06-24  |  2KB  |  64 lines

  1. @echo off
  2. REM DelTree1 - Delete a directory, including all files and subdirectories.  This is
  3. REM            slower than DelTree2, because it deletes one file at a time.
  4. if "%1"=="" GOTO SHOW_HOW
  5.  
  6. :This is a dangerious function, so make sure they really want it
  7.    ECHO THIS WILL DELETE ALL FILES AND DIRECTORIES UNDER %1
  8.    ECHO %1 MUST BE A VALID DIRECTORY AND YOU NEED MSDOS 5
  9.    CEnvi GetUKey.cmm ARE YOU SURE YOU WANT TO DO THIS? (Y/N)    yn
  10.    if N==%UKEY% GOTO FINI
  11.  
  12. :Check that it is a valid file name
  13.    CEnvi ValidDir.bat %1 COMPLAIN
  14.    if ERRORLEVEL 1 GOTO FINI
  15.  
  16. :Unset attributes so that all files can be deleted
  17.    attrib -H -S -R %1\*.* /s > NUL
  18.  
  19. :Delete each name in the directory and sub-directories
  20.    dir %1 /A-d /f /s /On | cenvi #include '%0,bat,:DelFiles'
  21.    :DelFiles   while ( NULL != (FileName = gets()) ) {
  22.    :DelFiles      printf("DEL %s\n",FileName)
  23.    :DelFiles      remove(FileName)
  24.    :DelFiles   }
  25.  
  26.  
  27. : Remove each directory, in reverse sorted order.  To do this will dump the
  28. : directories into a temporary file, and revers sort that file.
  29.    dir %1 /Ad /f /s > %1\DelTree1.tmp
  30.    sort /R < %1\DelTree1.tmp > %1\DelTree2.tmp
  31.    set TEMP_DIRS=%1\DelTree2.tmp
  32.    cenvi #include '%0,bat,:RemDirs'
  33.    :RemDirs if ( NULL == (fp = fopen(TEMP_DIRS,"r")) )
  34.    :RemDirs    printf("\aERROR OPENING FILE")
  35.    :RemDirs else {
  36.    :RemDirs    while ( NULL != (DirName = fgets(fp)) ) {
  37.    :RemDirs       if ( DirName[strlen(DirName)-1] == '\n' )
  38.    :RemDirs          DirName[strlen(DirName)-1] = 0
  39.    :RemDirs       if ( DirName[strlen(DirName)-1] != '.' ) {
  40.    :RemDirs          sprintf(Command,"RMDIR %s",DirName);
  41.    :RemDirs          printf("%s\n",Command)
  42.    :RemDirs          system(Command)
  43.    :RemDirs       }
  44.    :RemDirs    }
  45.    :RemDirs    fclose(fp)
  46.    :RemDirs }
  47.    set TEMP_DIRS=
  48.    del %1\DelTree?.tmp
  49.  
  50. :Finally, delete the directory itself
  51.    ECHO RMDIR %1
  52.    rmdir %1 > NUL
  53. GOTO FINI
  54.  
  55.  
  56. :SHOW_HOW
  57. ECHO  
  58. ECHO DelTree1.bat - Delete this directory and all files and subdirectories within it.
  59. ECHO  
  60. GOTO FINI
  61.  
  62. :FINI
  63. set UKEY=
  64.